package cate.game.pvp.eliterace.handler;

import cate.common.table.d.GDNotice;
import cate.game.chat.ChatContentParam;
import cate.game.notice.NoticeParam;
import cate.game.pvp.eliterace.data.EliteRaceRankRwd;
import cate.game.pvp.eliterace.data.EliteRaceRankRwdData;
import cate.game.role.RoleSnapshot;
import org.apache.commons.compress.utils.Lists;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class BothEliteRaceRankRwdOperation implements EliteRaceRankRwdOperation {

    private final EliteRaceRankRwdData rankRwdData;
    private final Consumer<NoticeParam> lampConsumer;

    public BothEliteRaceRankRwdOperation(Supplier<EliteRaceRankRwdData> rwdDataSupplier,
                                         Consumer<NoticeParam> lampConsumer) {
        this.rankRwdData = Objects.requireNonNull(rwdDataSupplier.get());
        this.lampConsumer = Objects.requireNonNull(lampConsumer);
    }

    @Override
    public void lamp(RoleSnapshot snapshot) {

    }

    @Override
    public void upsert(List<EliteRaceRankRwd> rankRwdList) {
        for (EliteRaceRankRwd rankRwd : rankRwdList) {
            if (!rankRwdData.contains(rankRwd.getSrvIdIndexName(), rankRwd.getIndexedKey())) {
                rankRwdData.addValue(rankRwd);
                rankRwdData.addIndex(rankRwd.getSrvIdIndexName(), rankRwd.getIndexedKey(), rankRwd);
            }
        }
    }

    @Override
    public List<EliteRaceRankRwd> query(QueryParam param) {
        Map<String, EliteRaceRankRwd> indexMap = rankRwdData.getIndex(param.getIndexedKey());
        return Objects.nonNull(indexMap) ?
                new ArrayList<>(indexMap.values())
                : Lists.newArrayList();
    }
}
